﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KnBinarySerializer.Brick
{
    internal class DateFormatter : IFormatter
    {
        public Type GetHandleType()
        {
            return typeof(DateTime);
        }

        public byte GetKey()
        {
            return 14;
        }
        public bool IsFixLen()
        {
            return true;
        }
        public object ReadBytes(BinarySerializeManager content, int maxLen, Type type)
        {
            long tick = content.ReadLong();
            return new DateTime(tick);
        }

        public int WriteBytes(BinarySerializeManager serial, object obj)
        {
            DateTime dateTime = (DateTime)obj;
            //byte[] content = RRQMBitConverter.Default.GetBytes(dateTime.Ticks);
            //serial.Write(content);
            //return content.Length;
            return serial.Write(dateTime.Ticks);
        }
    }
}
